﻿using UnityEngine;
using System.Collections;
using DICE_GS;

public class PlayerReadyState : MonoBehaviour {
	
	public GameObject[] playerChar;
	public GameObject[] playerFrame;
	public GameObject[] playerNick;
	public GameObject[] playerReadyStatus;
	
	public GameObject[] myUnitDeckImg;
	
	public GameObject readyBtn;
	public GameObject unReadyBtn;

	// Use this for initialization
	void Start () {
	
	}
	
	void ShowPanel(int index, bool bShow)
	{
		playerChar[index].SetActive(bShow);
		playerFrame[index].SetActive(bShow);
		playerNick[index].SetActive(bShow);
	}
	

	public void SetSlot(int index, string nick, int ready, int leaderId)
	{
		ShowPanel(index,true);
		if( playerNick[index].GetComponent<UILabel>().text != nick)
			playerNick[index].GetComponent<UILabel>().text = nick;
		if( ready == 0)
			playerReadyStatus[index].SetActive(false);
		else
			playerReadyStatus[index].SetActive(true);		
		
		CUnitData tmpUnitData = CUnitDataManager.Instance.GetUnitData(leaderId);
		if (tmpUnitData != null)
		{
			UISprite tmpSprite = playerChar[index].GetComponent<UISprite>() as UISprite;
			tmpSprite.spriteName = tmpUnitData.name;
		}		
	}
	
	public void ClearSlot(int index)
	{
		ShowPanel(index,false);
		playerReadyStatus[index].SetActive(false);
	}
	
	public void SetReady(bool isReady)
	{
		if(isReady) {
			unReadyBtn.SetActive(true);
			readyBtn.SetActive(false);
		}
		else {
			readyBtn.SetActive(true);
			unReadyBtn.SetActive(false);
		}		
	}
	
	public void ResetState()
	{
		for(int i=0; i<4; i++)
		{
			ShowPanel(i,false);
			playerReadyStatus[i].SetActive(false);
		}
			
	}
	
	public void SetState(int index, string nick , int state)
	{
		ShowPanel(index,true);
		if( state == 0)
			playerReadyStatus[index].SetActive(false);
		else
			playerReadyStatus[index].SetActive(true);
		playerNick[index].GetComponent<UILabel>().text = nick;
	}
	
	void OnReady()
	{
//		if (CNetworkManager.Instance.Connect)
//		{
//            if (StageManagerWrapper.Instance.FindPawn(StageManagerWrapper.m_MySID).ReadyStatus == ReadyStatus.RS_READY)
//            {
//                StageManagerWrapper.SendReadyStatus(ReadyStatus.RS_NOT_READY);
//            }
//            else
//            {
//                StageManagerWrapper.SendReadyStatus(ReadyStatus.RS_READY);
//            }
//		}		
	}	
	
	// Update is called once per frame
	void Update () {
	
	}
}
